package com.wyg.jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class JDBCTamplate {
	public Connection conn = null;

	public JDBCTamplate(Connection conn) {
		this.conn=conn;
	}

	public void insert(String sql,PreparedStatementSetter ps){
		try {
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ps.setValues(pstmt);
			pstmt.execute();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public ResultSet query(String sql,PreparedStatementSetter ps){
		ResultSet rs=null;
		try {
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ps.setValues(pstmt);
			rs=pstmt.executeQuery();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return rs;
	}
}
